package com.example.orchid.paper.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Stream 工具类
 * Created by Orchid on 2015-10-13.
 */
public class StreamUtils {
    public static void copy(final InputStream in, final OutputStream out) throws IOException {
        final int buff_size = 1024;
        byte[] buffer = new byte[buff_size];

        int count = 0;
        while ((count = in.read(buffer)) >= 0) {
            out.write(buffer, 0, count);
        }
    }

    public static void close(InputStream inputStream) {
        if (inputStream != null) {
            try {
                inputStream.close();
                inputStream = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(OutputStream outputStream) {
        if (outputStream != null) {
            try {
                outputStream.close();
                outputStream = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
